/*
 * libustream: User-space stackable streams
 * @(#) $Id: p_usmodules.h 2 2009-02-20 09:52:11Z mo@ilaven.net $
 */

/*
 * Copyright (c) 2002, 2008 Mo McRoberts.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The names of the author(s) of this software may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef P_USMODULES_H_
# define P_USMODULES_H_                1

# include <stdio.h>
# include <stdlib.h>
# include <pthread.h>
# include <sys/types.h>
# include <sys/socket.h>
# include <sys/ioctl.h>
# include <alloca.h>
# include <errno.h>
# include <stdarg.h>
# include <unistd.h>

# include "iri.h"
# include "com/com.h"
# include "ustream/IUStreamFactory.h"
# include "ustream/ustream.h"

# ifndef SOCK_MAXADDRLEN
#  define SOCK_MAXADDRLEN              255
# endif

extern com_result_t us__file_open(const iri_t *iri, int oflag, mode_t mode, IUStreamNode **out, int *fdout);
extern com_result_t us__fd_open(const iri_t *iri, int oflag, mode_t mode, IUStreamNode **out, int *fdout);

extern com_result_t us__rot13_push(IUStream *stream, IUStreamNode **out);

/* Default implementations */
extern com_result_t __stdcall UStream_Tail_GetChildNode(IUStreamNode *intf, IUStream *parent, IUStream *child, IUStreamNode **childNode);
extern com_result_t __stdcall UStream_Tail_Write(IUStreamNode *intf, IUStream *stream, const void *buf, size_t *buflen);
extern com_result_t __stdcall UStream_Tail_Read(IUStreamNode *intf, IUStream *stream, void *buf, size_t *buflen);
extern com_result_t __stdcall UStream_Tail_Pending(IUStreamNode *intf, IUStream *stream, size_t *out);
extern com_result_t __stdcall UStream_Tail_Accept(IUStreamNode *intf, IUStream *stream, IUStreamNode **out, int *fdout);

extern com_result_t __stdcall UStream_Head_GetChildNode(IUStreamNode *intf, IUStream *parent, IUStream *child, IUStreamNode **childNode);
extern com_result_t __stdcall UStream_Head_Write(IUStreamNode *intf, IUStream *stream, const void *buf, size_t *buflen);
extern com_result_t __stdcall UStream_Head_Read(IUStreamNode *intf, IUStream *stream, void *buf, size_t *buflen);
extern com_result_t __stdcall UStream_Head_Pending(IUStreamNode *intf, IUStream *stream, size_t *out);
extern com_result_t __stdcall UStream_Head_Accept(IUStreamNode *intf, IUStream *stream, IUStreamNode **out, int *fdout);


#endif /* !P_USMODULES_H_ */

/* F3BE356D-63D6-4356-988B-25AC6360513E */
DEFINE_GUID(CLSID_UStream_FD, 0xF3BE356D, 0x63D6, 0x4356, 0x98, 0x8B, 0x25, 0xAC, 0x63, 0x60, 0x51, 0x3E);
/* 0A4D6E68-397A-46A9-A3AE-943826B38B54 */
DEFINE_GUID(CLSID_UStream_File, 0x0A4D6E68, 0x397A, 0x46A9, 0xA3, 0xAE, 0x94, 0x38, 0x26, 0xB3, 0x8B, 0x54);
/* 4DE8B2F6-6176-45FB-B822-973D1A0F8C38 */
DEFINE_GUID(CLSID_UStream_Rot13, 0x4DE8B2F6, 0x6176, 0x45FB, 0xB8, 0x22, 0x97, 0x3D, 0x1A, 0x0F, 0x8C, 0x38);
